package com.hxl.tech.gateway.auth.config;


import com.hxl.tech.gateway.auth.context.ContextInterceptor;
import com.hxl.tech.gateway.auth.context.RequestInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * Web配置
 * @author soliddq
 * @date 2023-09-20
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Bean
    public FilterRegistrationBean<AllowAllCorsFilter> corsFilterFilterRegistrationBean() {
        FilterRegistrationBean<AllowAllCorsFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new AllowAllCorsFilter());
        filterRegistrationBean.setName("corsFilter");
        filterRegistrationBean.setOrder(600);
        return filterRegistrationBean;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new ContextInterceptor()).addPathPatterns("/**");
        registry.addInterceptor(new RequestInterceptor()).addPathPatterns("/**");
        WebMvcConfigurer.super.addInterceptors(registry);
    }

}
